# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=ovn
pkgver=22.03.0
ovs_pkgver=2.17.1
pkgrel=0
pkgdesc="Open Virtual Network"
url="ttps://www.ovn.org"
arch="all"
license="Apache-2.0"
makedepends="automake
	autoconf
	libtool
	libcap-ng-dev
	linux-headers
	openssl-dev
	python3
	unbound-dev
	"
subpackages="$pkgname-dev $pkgname-doc"
giturl="https://github.com/openvswitch/ovs.git"
_gitrev="498cedc"
options="!check" # a couple of tests fail, disabling for now
source="$pkgname-$pkgver.tar.gz::https://github.com/ovn-org/ovn/archive/refs/tags/v$pkgver.tar.gz
	https://dev.alpinelinux.org/archive/ovn/openvswitch-$ovs_pkgver-$_gitrev.tar.gz"

snapshot() {
	mkdir -p "$srcdir"
	cd "$srcdir"
	if ! [ -d ovs ]; then git clone $giturl; fi
	cd ovs
	git archive --prefix=openvswitch-$ovs_pkgver/ -o "$srcdir"/openvswitch-$ovs_pkgver-$_gitrev.tar.gz $_gitrev
	scp "$srcdir"/openvswitch-$ovs_pkgver-$_gitrev.tar.gz dev.alpinelinux.org:/archive/$pkgname/
}

prepare() {
	default_prepare
	./boot.sh
}

build() {
	export CFLAGS="$CFLAGS -fPIC"
	# First OpenVSwitch must be built
	# Taking the same configure options from openvswitch APKBUILD
	cd "$srcdir"/openvswitch-$ovs_pkgver
	./boot.sh
        ./configure --prefix=/usr \
                --sysconfdir=/etc \
                --mandir=/usr/share/man \
                --infodir=/usr/share/info \
                --localstatedir=/var \
                --enable-ndebug \
                --enable-libcap-ng \
                PYTHON=/usr/bin/python3
	make

	# now building OVN
	cd "$builddir"
	./configure --prefix=/usr \
		--sysconfdir=/etc \
                --localstatedir=/var \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--enable-shared \
		--with-ovs-source=../openvswitch-$ovs_pkgver \
		--with-ovs-build=../openvswitch-$ovs_pkgver
	make
}

package() {
	# parallel install issue
	make -j1 DESTDIR="$pkgdir" install

}

check() {
	make check
}

sha512sums="
b47ad17ada4bbaadd4a7baf194512f327c9838aa779a811c4ba1859e6ebcf380e56cb3bf4786d32ef1cdef4fe285351996dccf740b74982f195c6b19feb75ccb  ovn-22.03.0.tar.gz
5d1fb0fb5eb070c8712759131f4c86915ab7b9075a1f5d136bea7b66efdcf55fd9aef79768f6431582aba9baddec4514200e2998abc3a37e01e5f0e186170b86  openvswitch-2.17.1-498cedc.tar.gz
"
